home *** CD-ROM | disk | FTP | other *** search
/ CICA 1997 August / CICA - The Ultimate Collection of Shareware for Windows (Walnut Creek) (August 1997) (Disc 1).iso / utils / unix / unzip520 / wingui / wndproc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-28  |  56.3 KB  |  1,377 lines

  1. /* Windows Info-ZIP Unzip Window Procedure, wndproc.c.
  2.  * Author: Robert A. Heath, 157 Chartwell Rd., Columbia, SC 29210
  3.  * I, Robert Heath, place this source code module in the public domain.
  4.  *
  5.  * Modifications: 1995 M. White
  6.  */
  7.  
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <time.h>
  11. #include <string.h>
  12. #include <stdio.h>
  13.  
  14. #include "wingui\wizunzip.h"
  15. #include "wingui\helpids.h"
  16. #include "wingui\password.h"
  17.  
  18. #define UNZIP_INTERNAL
  19. #include "unzip.h"
  20. #include "crypt.h"
  21. #include <shellapi.h>
  22. #include <lzexpand.h>
  23.  
  24. #define MAKE_TABSTOP_TABLE_ENTRY(WNDHANDLE, ID) \
  25.     { \
  26.     TabStopTable[ID - TABSTOP_ID_BASE].lpfnOldFunc = \
  27.        (FARPROC)GetWindowLong(WNDHANDLE, GWL_WNDPROC); \
  28.     SetWindowLong(WNDHANDLE, GWL_WNDPROC, (LONG)lpfnKbd); \
  29.     TabStopTable[ID - TABSTOP_ID_BASE].hWnd = WNDHANDLE; \
  30.     }
  31.  
  32. #ifdef USEWIZUNZDLL
  33. char Far HeadersS[]  = " Length    Date    Time    Name";
  34. char Far HeadersS1[] = " ------    ----    ----    ----";
  35. char Far HeadersL[]  =
  36.   " Length  Method   Size  Ratio   Date    Time   CRC-32     Name";
  37. char Far HeadersL1[] =
  38.   " ------  ------   ----  -----   ----    ----   ------     ----";
  39. char Far *Headers[][2] = { {HeadersS, HeadersS1}, {HeadersL, HeadersL1} };
  40. #endif
  41.  
  42. /* Forward Refs
  43.  */
  44. static void GetArchiveDir(LPSTR lpszDestDir);
  45. void GetDirectory(LPSTR lpDir);
  46.  
  47. HWND hPatternSelectDlg; /* pattern select modeless dialog   */
  48. static UINT uCommDlgHelpMsg;   /* common dialog help message ID */
  49. static DWORD dwCommDlgHelpId = HELPID_HELP; /* what to pass to WinHelp() */
  50. static char szFormatKeyword[2][6] = { "short", "long" };
  51. static BOOL move_flag = FALSE;
  52. static BOOL rename_flag = FALSE;
  53.  
  54. LPSTR lpchLast;
  55.  
  56. /* Trailers are the lines just above the totals */
  57. static char * __based(__segname("STRINGS_TEXT")) szTrailers[2] = {
  58. " ------                    -------",
  59. " ------          ------  ---                              -------"
  60. } ;
  61. static char __based(__segname("STRINGS_TEXT")) szCantChDir[] =
  62.    "Internal error: Cannot change directory. Common dialog error code is 0x%lX.";
  63.  
  64. /* size of char in SYSTEM font in pixels */
  65. #ifndef WIN32
  66. short dxChar, dyChar;
  67. #else
  68. long dxChar, dyChar;
  69. #endif
  70.  
  71. /* button control table -- one entry for
  72.  * each of 4 entries. Indexed by the window ID relative to
  73.  * the first tabstop (TABSTOP_ID_BASE).
  74.  */
  75. TabStopEntry TabStopTable[TABSTOP_TABLE_ENTRIES];
  76.  
  77. LPSTR lstrrchr(LPSTR lpszSrc, char chFind)
  78. {
  79. LPSTR   lpszFound = (LPSTR)0;
  80. LPSTR   lpszT;
  81.  
  82. if ( lpszSrc )
  83.    {
  84.    for (lpszT = lpszSrc; *lpszT; ++lpszT)
  85.        {
  86.        if ((*lpszT) == chFind)
  87.           lpszFound = lpszT;
  88.        }
  89.    }
  90. return lpszFound;
  91. }
  92.  
  93. /* Copy only the path portion of current file name into
  94.  * given buffer, lpszDestDir, translate into ANSI.
  95.  */
  96. static void GetArchiveDir(LPSTR lpszDestDir)
  97. {
  98. LPSTR lpchLast;
  99.  
  100. /* strip off filename to make directory name    */
  101. OemToAnsi(lpumb->szFileName, lpszDestDir);
  102. if ((lpchLast = lstrrchr(lpszDestDir, '\\'))!=0)
  103.    *lpchLast = '\0';
  104. else if ((lpchLast = lstrrchr(lpszDestDir, ':'))!=0)
  105.    *(++lpchLast) = '\0'; /* clobber char AFTER the colon! */
  106. }
  107.  
  108. void GetDirectory(LPSTR lpDir)
  109. {
  110. LPSTR lpchLast;
  111. /* If no '\\' then set directory name to "" */
  112. if ((lpchLast = lstrrchr(lpDir, '\\')) == 0)
  113.    {
  114.    lpDir[0] = '\0';
  115.    return;
  116.    }
  117. /* strip off filename to make directory name    */
  118. if ((lpchLast = lstrrchr(lpDir, '\\'))!=0)
  119.    *lpchLast = '\0';
  120. else if ((lpchLast = lstrrchr(lpDir, ':'))!=0)
  121.    *(++lpchLast) = '\0'; /* clobber char AFTER the colon! */
  122. }
  123.  
  124. /*
  125.  * FUNCTION: SetCaption(HWND hWnd)
  126.  * PURPOSE: Set new caption for main window
  127.  */
  128. void
  129. SetCaption(HWND hWnd)
  130. {
  131. #define SIMPLE_NAME_LEN 15
  132. static BOOL FirstTime = TRUE;
  133. WORD wMenuState;
  134. char szSimpleFileName[SIMPLE_NAME_LEN+1];  /* just the 8.3 part in ANSI char set */
  135. LPSTR lpszFileNameT;        /* pointer to simple filename               */
  136. BOOL    fIconic = IsIconic(hWnd);   /* is window iconic ?   */
  137. BOOL fWndEnabled; /* Is button to be enabled? */
  138.  
  139. /* point to simple filename in OEM char set */
  140. if ((((lpszFileNameT = lstrrchr(lpumb->szFileName, '\\'))!=0) ||
  141.    ((lpszFileNameT = lstrrchr(lpumb->szFileName, ':')))!=0))
  142.    lpszFileNameT++;
  143. else
  144.    lpszFileNameT = lpumb->szFileName;
  145.  
  146. #ifndef WIN32
  147. _fstrncpy(szSimpleFileName, lpszFileNameT, SIMPLE_NAME_LEN);
  148. #else
  149. strncpy(szSimpleFileName, lpszFileNameT, SIMPLE_NAME_LEN);
  150. #endif
  151. szSimpleFileName[SIMPLE_NAME_LEN] = '\0'; /* force termination */
  152.  
  153. wMenuState = (WORD)(szSimpleFileName[0] ? MF_ENABLED : MF_GRAYED);
  154. fWndEnabled = (BOOL) (szSimpleFileName[0] ? TRUE : FALSE);
  155. /* Enable/Disable menu items */
  156. EnableMenuItem(hMenu, IDM_SELECT_ALL, wMenuState|MF_BYCOMMAND);
  157. EnableMenuItem(hMenu, IDM_DESELECT_ALL, wMenuState|MF_BYCOMMAND);
  158. EnableMenuItem(hMenu, IDM_SELECT_BY_PATTERN, wMenuState|MF_BYCOMMAND);
  159.  
  160. /* Enable/Disable buttons */
  161. if (!FirstTime)
  162.    {
  163.    WinAssert(hSelectAll);
  164.    EnableWindow( hSelectAll, fWndEnabled);
  165.    WinAssert(hDeselectAll);
  166.    EnableWindow( hDeselectAll, fWndEnabled);
  167.    WinAssert(hSelectPattern);
  168.    EnableWindow( hSelectPattern, fWndEnabled);
  169.    }
  170.  
  171. if (!szSimpleFileName[0])
  172.    lstrcpy(szSimpleFileName, "No Zip File");
  173. OemToAnsi(szSimpleFileName, szSimpleFileName);
  174. wsprintf(lpumb->szBuffer, "%s - %s %s %s",
  175.                (LPSTR)szAppName,
  176.                (LPSTR)(szSimpleFileName),
  177.                (LPSTR)(!fIconic && lpumb->szUnzipToDirName[0] ? " - " : ""),
  178.                (LPSTR)(!fIconic ? lpumb->szUnzipToDirName : ""));
  179. SetWindowText(hWnd, lpumb->szBuffer);
  180. FirstTime = FALSE;
  181. }
  182.  
  183. static void ManageStatusWnd(WPARAM wParam);
  184. static void ManageStatusWnd(WPARAM wParam)
  185. {
  186. int nWndState;  /* ShowWindow state     */
  187. BOOL fWndEnabled;   /* Enable Window state */
  188.  
  189. if (LOWORD(wParam) == IDM_SPLIT)
  190.    {
  191.    WinAssert(hWndStatus);
  192.    ShowWindow(hWndStatus, SW_RESTORE);
  193.    UpdateWindow(hWndStatus);
  194.    fWndEnabled = TRUE;
  195.    nWndState = SW_SHOWNORMAL;
  196.    }
  197. else    /* Message window goes to maximum state     */
  198.    {
  199.    nWndState = SW_HIDE;    /* assume max state     */
  200.    fWndEnabled = FALSE;
  201.    }
  202.  
  203. wWindowSelection = LOWORD(wParam); /* window selection: listbox, status, both */
  204. WinAssert(hWndList);
  205. EnableWindow( hWndList, fWndEnabled);
  206. UpdateWindow( hWndList);
  207. ShowWindow( hWndList, nWndState);
  208.  
  209. if (LOWORD(wParam) == IDM_SPLIT) /* uncover buttons    */
  210.    {
  211.    UpdateButtons(hWndMain);    /* restore to proper state  */
  212.    }
  213. else
  214.    {   /* Disable Extract, Display, Test, and Comment buttons */
  215.    WinAssert(hExtract);
  216.    EnableWindow( hExtract, fWndEnabled);
  217.    WinAssert(hTest);
  218.    EnableWindow( hTest, fWndEnabled);
  219.    WinAssert(hDisplay);
  220.    EnableWindow( hDisplay, fWndEnabled);
  221.    WinAssert(hShowComment);
  222.    EnableWindow( hShowComment, fWndEnabled);
  223.    }
  224.  
  225. UpdateWindow(hExtract);
  226. UpdateWindow(hTest);
  227. UpdateWindow(hDisplay);
  228. UpdateWindow(hShowComment);
  229.  
  230. if (LOWORD(wParam) == IDM_MAX_STATUS)   /* message box max'd out */
  231.    {
  232.    WinAssert(hWndStatus);
  233.    ShowWindow(hWndStatus, SW_SHOWMAXIMIZED);
  234.    }
  235. SetFocus(hWndStatus);
  236. SizeWindow(hWndMain, FALSE);
  237. }
  238.  
  239. /*
  240.  * FUNCTION: WizunzipWndProc(HWND, unsigned, WORD, LONG)
  241.  *
  242.  * PURPOSE:  Processes messages
  243.  *
  244.  * MESSAGES:
  245.  *
  246.  * WM_DESTROY      - destroy window
  247.  * WM_SIZE         - window size has changed
  248.  * WM_QUERYENDSESSION - willing to end session?
  249.  * WM_ENDSESSION   - end Windows session
  250.  * WM_CLOSE        - close the window
  251.  * WM_SIZE         - window resized
  252.  * WM_PAINT        - windows needs to be painted
  253.  * WM_DROPFILES    - open a dropped file
  254.  * COMMENTS:
  255.  * WM_COMMAND processing:
  256.  *    IDM_OPEN -  open a new file.
  257.  *    IDM_EXIT -  exit.
  258.  *    IDM_ABOUT - display "About" box.
  259.  */
  260. long WINAPI WizUnzipWndProc(HWND hWnd, WORD wMessage, WPARAM wParam, LPARAM lParam)
  261. {
  262.  
  263. HDC hDC;                /* device context       */
  264. TEXTMETRIC    tm;           /* text metric structure    */
  265. POINT point;
  266. char drive;
  267. #ifndef WIN32
  268. FARPROC lpfnAbout, lpfnSelectDir;
  269. #endif
  270. FARPROC lpfnKbd;
  271. char *ptr;
  272.  
  273. switch (wMessage)
  274.     {
  275.     case WM_CREATE: /* create  window       */
  276.       hInst = ((LPCREATESTRUCT)lParam)->hInstance;
  277.       lpfnKbd = MakeProcInstance((FARPROC)KbdProc, hInst);
  278.       hAccTable = LoadAccelerators(hInst, "WizunzipAccels");
  279.       hBrush = CreateSolidBrush(GetSysColor(BG_SYS_COLOR)); /* background */
  280.  
  281.       hMenu = GetMenu(hWnd);
  282.       /* Check Menu items to reflect .INI settings */
  283.       CheckMenuItem(hMenu, IDM_RECR_DIR_STRUCT, MF_BYCOMMAND |
  284.                             (uf.fRecreateDirs ? MF_CHECKED : MF_UNCHECKED));
  285.       CheckMenuItem(hMenu, IDM_SHOW_BUBBLE_HELP, MF_BYCOMMAND |
  286.                             (uf.fShowBubbleHelp ? MF_CHECKED : MF_UNCHECKED));
  287.       CheckMenuItem(hMenu, (IDM_SHORT+uf.fFormatLong), MF_BYCOMMAND | MF_CHECKED);
  288.       CheckMenuItem(hMenu, IDM_PROMPT_TO_OVERWRITE, MF_BYCOMMAND |
  289.                             (lpDCL->PromptToOverwrite ? MF_CHECKED : MF_UNCHECKED));
  290.       if (!lpDCL->PromptToOverwrite)
  291.          {
  292.          ModifyMenu(hMenu, IDM_OVERWRITE, MF_BYCOMMAND |
  293.                  MF_ENABLED, IDM_OVERWRITE,
  294.                  (lpDCL->Overwrite ? "Always Overwrite Existing Files":
  295.                  "Never Overwrite Existing Files"));
  296.          CheckMenuItem(hMenu, IDM_OVERWRITE, MF_BYCOMMAND |MF_CHECKED);
  297.          CheckMenuItem(hMenu, IDM_EXTRACT_ONLY_NEWER, MF_BYCOMMAND |
  298.                             (lpDCL->ExtractOnlyNewer ? MF_CHECKED : MF_UNCHECKED));
  299.          }
  300.       else
  301.          {
  302.          EnableMenuItem(hMenu, IDM_OVERWRITE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
  303.          EnableMenuItem(hMenu, IDM_EXTRACT_ONLY_NEWER, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
  304.          }
  305.       CheckMenuItem(hMenu, IDM_TRANSLATE, MF_BYCOMMAND |
  306.                             (uf.fTranslate ? MF_CHECKED : MF_UNCHECKED));
  307.       CheckMenuItem(hMenu, IDM_SPACE_TO_UNDERSCORE, MF_BYCOMMAND |
  308.                             (lpDCL->SpaceToUnderscore ? MF_CHECKED : MF_UNCHECKED));
  309.       CheckMenuItem(hMenu, IDM_SAVE_UNZIP_TO_DIR, MF_BYCOMMAND |
  310.                             (uf.fSaveUnZipToDir ? MF_CHECKED : MF_UNCHECKED));
  311.       CheckMenuItem(hMenu, IDM_SAVE_UNZIP_FROM_DIR, MF_BYCOMMAND |
  312.                             (uf.fSaveUnZipFromDir ? MF_CHECKED : MF_UNCHECKED));
  313.       CheckMenuItem(hMenu, wLBSelection, MF_BYCOMMAND | MF_CHECKED);
  314.       CheckMenuItem(hMenu, IDM_UNZIP_TO_ZIP_DIR, MF_BYCOMMAND |
  315.                             (uf.fUnzipToZipDir ? MF_CHECKED : MF_UNCHECKED));
  316.       EnableMenuItem(hMenu, IDM_CHDIR, MF_BYCOMMAND |
  317.                             (uf.fUnzipToZipDir ? MF_GRAYED : MF_ENABLED));
  318.       CheckMenuItem(hMenu, IDM_AUTOCLEAR_STATUS, MF_BYCOMMAND |
  319.                             (uf.fAutoClearStatus ? MF_CHECKED : MF_UNCHECKED));
  320.       CheckMenuItem(hMenu, IDM_AUTOCLEAR_DISPLAY, MF_BYCOMMAND |
  321.                             (uf.fAutoClearDisplay ? MF_CHECKED : MF_UNCHECKED));
  322.       EnableMenuItem(hMenu, IDM_COPY, MF_GRAYED);
  323.  
  324.       /* Get an hourglass cursor to use during file transfers */
  325.       hHourGlass = LoadCursor(0, IDC_WAIT);
  326.  
  327.       hFixedFont = GetStockObject(SYSTEM_FIXED_FONT);
  328.       hDC = GetDC(hWnd);  /* get device context */
  329.       hOldFont = SelectObject(hDC, hFixedFont);
  330.       GetTextMetrics(hDC, &tm);
  331.       ReleaseDC(hWnd, hDC);
  332.       dxChar = tm.tmAveCharWidth;
  333.       dyChar = tm.tmHeight + tm.tmExternalLeading;
  334.  
  335.       WinAssert(hWnd);
  336. #ifndef WIN32
  337.       hWndList = CreateWindow("listbox", NULL,
  338.                         WS_CHILD|WS_VISIBLE|WS_BORDER|WS_VSCROLL|LBS_NOTIFY|
  339.                         LBS_EXTENDEDSEL,
  340.                         0, 0,
  341.                         0, 0,
  342.                         hWnd, (HMENU)IDM_LISTBOX,
  343.                         GetWindowWord (hWnd, GWW_HINSTANCE), NULL);
  344. #else
  345.       hWndList = CreateWindow("listbox", NULL,
  346.                         WS_CHILD|WS_VISIBLE|WS_BORDER|WS_VSCROLL|LBS_NOTIFY|
  347.                         LBS_EXTENDEDSEL,
  348.                         0, 0,
  349.                         0, 0,
  350.                         hWnd, (HMENU)IDM_LISTBOX,
  351.                         (HANDLE)GetWindowLong (hWnd, GWL_HINSTANCE), NULL);
  352. #endif
  353.       WinAssert(hWndList);
  354.       MAKE_TABSTOP_TABLE_ENTRY(hWndList, IDM_LISTBOX);
  355.       SendMessage(hWndList, WM_SETFONT, (WPARAM)hFixedFont, FALSE);
  356.       ShowWindow(hWndList, SW_SHOW);
  357.       UpdateWindow(hWndList);         /* show it now! */
  358.       WinAssert(hWnd);
  359.  
  360. #ifndef WIN32
  361.       hWndStatus = CreateWindow(szStatusClass, "Status/Display",
  362.                             WS_CHILD|WS_SYSMENU|WS_VISIBLE|WS_BORDER|WS_HSCROLL|WS_VSCROLL|WS_MAXIMIZEBOX|WS_CAPTION,
  363.                             0, 0,
  364.                             0, 0,
  365.                             hWnd, (HMENU)IDM_STATUS,
  366.                             GetWindowWord (hWnd, GWW_HINSTANCE), NULL);
  367. #else
  368.       hWndStatus = CreateWindow(szStatusClass, "Status/Display",
  369.                             WS_CHILD|WS_SYSMENU|WS_VISIBLE|WS_BORDER|WS_HSCROLL|WS_VSCROLL|WS_MAXIMIZEBOX|WS_CAPTION,
  370.                             0, 0,
  371.                             0, 0,
  372.                             hWnd, (HMENU)IDM_STATUS,
  373.                             (HANDLE)GetWindowLong (hWnd, GWL_HINSTANCE), NULL);
  374. #endif
  375.       WinAssert(hWndStatus);
  376.       SendMessage(hWndStatus, WM_SETFONT, (WPARAM)hFixedFont, TRUE);
  377.       MAKE_TABSTOP_TABLE_ENTRY(hWndStatus, IDM_STATUS);
  378.  
  379.       /* if file spec'd on entry */
  380.       if (lpumb->szFileName[0])
  381.          {
  382.          LPSTR lpch;
  383.          extern int ofretval; /* return value from initial open if filename given
  384.                                 during WinMain() */
  385.          /* If valid filename change dir to where it lives */
  386.          if (ofretval >= 0)
  387.             {
  388.             GetArchiveDir(lpumb->szDirName); /* get archive dir. in ANSI char set */
  389.             if (uf.fUnzipToZipDir || /* unzipping to same directory as archive */
  390.                lpumb->szUnzipToDirName[0] == '\0') /* or no default */
  391.                {
  392.                /* take only path portion */
  393.                lstrcpy(lpumb->szUnzipToDirName, lpumb->szDirName);
  394.                }
  395.             lstrcpy(lpumb->szBuffer, lpumb->szDirName);
  396.             DlgDirList(hWnd, lpumb->szBuffer, 0, 0, 0); /* go to where archive lives */
  397.             }
  398.          else /* bad file name */
  399.             {
  400.             OemToAnsi(lpumb->szFileName, lpumb->szFileName); /* temporarily OEM */
  401.             if ((((lpch = lstrrchr(lpumb->szFileName, '\\'))!=0) ||
  402.                  ((lpch = lstrrchr(lpumb->szFileName, ':')))!=0))
  403.                lpch++; /* point to filename */
  404.             else
  405.                lpch = lpumb->szFileName;
  406.  
  407.             wsprintf (lpumb->szBuffer, "Cannot open %s", lpch);
  408.             MessageBox (hWnd, lpumb->szBuffer, szAppName, MB_ICONINFORMATION | MB_OK);
  409.             lpumb->szFileName[0] = '\0'; /* pretend filename doesn't exist  */
  410.             lpumb->szDirName[0] = '\0'; /* pretend archive dir. doesn't exist  */
  411.             }
  412.         }
  413.         SetCaption(hWnd);
  414.         UpdateListBox(hWnd);
  415.         SendMessage(hWndList, LB_SETSEL, 1, 0L);
  416.         uCommDlgHelpMsg = RegisterWindowMessage((LPSTR)HELPMSGSTRING); /* register open help message */
  417.  
  418.         if ( uf.fCanDragDrop )
  419.             DragAcceptFiles( hWnd, TRUE );
  420.         break;
  421.  
  422.     case WM_SETFOCUS:
  423.         SetFocus((wWindowSelection == IDM_MAX_STATUS) ? hWndStatus : hWndList);
  424.         break;
  425.  
  426.     case WM_ACTIVATE:
  427.         SetCaption(hWnd);
  428.         return DefWindowProc(hWnd, wMessage, wParam, lParam);
  429.  
  430.     case WM_SIZE:
  431.         SizeWindow(hWnd, FALSE);
  432.         break;
  433.  
  434.     /*
  435.      * NOTE: WM_CTLCOLOR is not a supported code under Win 32
  436.      */
  437. #ifdef WIN32
  438.     case WM_CTLCOLORBTN:
  439.     case WM_CTLCOLORSTATIC:
  440. #else
  441.     case WM_CTLCOLOR: /* color background of buttons and statics */
  442.         if (HIWORD(lParam) == CTLCOLOR_STATIC)
  443. #endif
  444.            {
  445.            SetBkMode((HDC)wParam, TRANSPARENT);
  446.            SetBkColor((HDC)wParam, GetSysColor(BG_SYS_COLOR)); /* custom b.g. color */
  447.            SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
  448.            UnrealizeObject(hBrush);
  449.            point.x = point.y = 0;
  450.            ClientToScreen(hWnd, &point);
  451. #ifndef WIN32
  452.            SetBrushOrg((HDC)wParam, point.x, point.y);
  453. #else
  454.            SetBrushOrgEx((HDC)wParam, point.x, point.y, NULL);
  455. #endif
  456.            return ((DWORD)hBrush);
  457.            }
  458.         /* fall thru to WM_SYSCOMMAND */
  459.  
  460.     case WM_SYSCOMMAND:
  461.         return DefWindowProc( hWnd, wMessage, wParam, lParam );
  462.  
  463.    case WM_INITMENUPOPUP: /* popup menu pre-display      */
  464.       {
  465. /*   BOOL bOutcome; MW: Removed to allow multiple pop-up menus */
  466.  
  467.       switch  (LOWORD(lParam)) {
  468.       case EDIT_MENUITEM_POS: /* index of Edit pop-up      */
  469. /*         bOutcome = EnableMenuItem((HMENU)wParam, IDM_COPY, */
  470.          EnableMenuItem((HMENU)wParam, IDM_COPY,
  471.             (UINT)(StatusInWindow() ? MF_ENABLED : MF_GRAYED));
  472.          EnableWindow(hCopyStatus, (UINT)(StatusInWindow() ? TRUE : FALSE));
  473.  
  474. /*         assert(bOutcome != -1);    -1 => Menu item doesn't exist */
  475.          break;
  476.       }
  477.       }
  478.       break;
  479.  
  480.     case WM_COMMAND:
  481.         /* Was F1 just pressed in a menu, or are we in help mode */
  482.         /* (Shift-F1)? */
  483.  
  484.         if (uf.fHelp)
  485.            {
  486.            DWORD dwHelpContextId =
  487.               (LOWORD(wParam) == IDM_OPEN)            ? (DWORD) HELPID_OPEN :
  488.               (LOWORD(wParam) == IDM_EXIT)            ? (DWORD) HELPID_EXIT_CMD :
  489.               (LOWORD(wParam) == IDM_CHDIR)           ? (DWORD) HELPID_CHDIR :
  490.               (LOWORD(wParam) == IDM_SHORT)           ? (DWORD) HELPID_SHORT :
  491.               (LOWORD(wParam) == IDM_LONG)            ? (DWORD) HELPID_LONG :
  492.               (LOWORD(wParam) == IDM_HELP)            ? (DWORD) HELPID_HELP :
  493.               (LOWORD(wParam) == IDM_HELP_HELP)       ? (DWORD) HELPID_HELP_HELP :
  494.               (LOWORD(wParam) == IDM_ABOUT)           ? (DWORD) HELPID_ABOUT :
  495.               (LOWORD(wParam) == IDM_RECR_DIR_STRUCT) ? (DWORD) HELPID_RECR_DIR_STRUCT :
  496.               (LOWORD(wParam) == IDM_SHOW_BUBBLE_HELP) ? (DWORD) HELPID_SHOW_BUBBLE_HELP :
  497.               (LOWORD(wParam) == IDM_OVERWRITE)       ? (DWORD) HELPID_OVERWRITE :
  498.               (LOWORD(wParam) == IDM_PROMPT_TO_OVERWRITE) ? (DWORD) HELPID_PROMPT_TO_OVERWRITE :
  499.               (LOWORD(wParam) == IDM_TRANSLATE)       ? (DWORD) HELPID_TRANSLATE :
  500.               (LOWORD(wParam) == IDM_UNZIP_TO_ZIP_DIR)? (DWORD) HELPID_UNZIP_TO_ZIP_DIR :
  501.               (LOWORD(wParam) == IDM_UNZIP_FROM_DIR)? (DWORD) HELPID_UNZIP_FROM_DIR :
  502.               (LOWORD(wParam) == IDM_LISTBOX)         ? (DWORD) HELPID_LISTBOX :
  503.               (LOWORD(wParam) == IDM_EXTRACT)         ? (DWORD) HELPID_EXTRACT :
  504.               (LOWORD(wParam) == IDM_DISPLAY)         ? (DWORD) HELPID_DISPLAY :
  505.               (LOWORD(wParam) == IDM_TEST)            ? (DWORD) HELPID_TEST :
  506.               (LOWORD(wParam) == IDM_SHOW_COMMENT)    ? (DWORD) HELPID_SHOW_COMMENT :
  507.               (LOWORD(wParam) == IDM_LB_EXTRACT)      ? (DWORD) HELPID_LB_EXTRACT :
  508.               (LOWORD(wParam) == IDM_LB_DISPLAY)      ? (DWORD) HELPID_LB_DISPLAY :
  509.               (LOWORD(wParam) == IDM_LB_TEST)         ? (DWORD) HELPID_LB_TEST :
  510.               (LOWORD(wParam) == IDM_DESELECT_ALL)    ? (DWORD) HELPID_DESELECT_ALL :
  511.               (LOWORD(wParam) == IDM_SELECT_ALL)      ? (DWORD) HELPID_SELECT_ALL :
  512.               (LOWORD(wParam) == IDM_SELECT_BY_PATTERN) ? (DWORD) HELPID_SELECT_BY_PATTERN :
  513.               (LOWORD(wParam) == IDM_AUTOCLEAR_STATUS) ? (DWORD) HELPID_AUTOCLEAR_STATUS :
  514.               (LOWORD(wParam) == IDM_AUTOCLEAR_DISPLAY) ? (DWORD) HELPID_AUTOCLEAR_DISPLAY :
  515.               (LOWORD(wParam) == IDM_CLEAR_STATUS)    ? (DWORD) HELPID_CLEAR_STATUS :
  516.               (LOWORD(wParam) == IDM_SOUND_OPTIONS)  ? (DWORD) HELPID_SOUND_OPTIONS :
  517.               (LOWORD(wParam) == IDM_MAX_LISTBOX)  ? (DWORD) HELPID_MAX_LISTBOX :
  518.               (LOWORD(wParam) == IDM_MAX_STATUS)  ? (DWORD) HELPID_MAX_STATUS :
  519.               (LOWORD(wParam) == IDM_SPLIT)  ? (DWORD) HELPID_SPLIT :
  520.               (LOWORD(wParam) == IDM_SAVE_UNZIP_FROM_DIR)  ? (DWORD) HELPID_SAVE_UNZIP_FROM_DIR :
  521.               (LOWORD(wParam) == IDM_SAVE_UNZIP_TO_DIR)  ? (DWORD) HELPID_SAVE_UNZIP_TO_DIR :
  522.               (LOWORD(wParam) == IDM_EXTRACT_ONLY_NEWER)  ? (DWORD) HELPID_EXTRACT_ONLY_NEWER :
  523.               (LOWORD(wParam) == IDM_SPACE_TO_UNDERSCORE)  ? (DWORD) HELPID_SPACE_TO_UNDERSCORE :
  524.               (LOWORD(wParam) == IDM_EDIT)  ? (DWORD) HELPID_EDIT :
  525.               (LOWORD(wParam) == IDM_PATH)  ? (DWORD) HELPID_PATH :
  526.               (LOWORD(wParam) == IDM_COMMENT)  ? (DWORD) HELPID_COMMENT :
  527.               (LOWORD(wParam) == IDM_COPY)  ? (DWORD) HELPID_COPY :
  528.               (LOWORD(wParam) == IDM_STATUS)  ? (DWORD) HELPID_STATUS :
  529.               (LOWORD(wParam) == IDM_CHDIR)  ? (DWORD) HELPID_CHDIR :
  530.               (LOWORD(wParam) == IDM_PASSWORD_HELP)  ? (DWORD) HELPID_PASSWORD :
  531.               (LOWORD(wParam) == IDM_COPY_ARCHIVE)  ? (DWORD) HELPID_COPY_ARCHIVE :
  532.               (LOWORD(wParam) == IDM_MOVE_ARCHIVE)  ? (DWORD) HELPID_MOVE_ARCHIVE :
  533.               (LOWORD(wParam) == IDM_DELETE_ARCHIVE)  ? (DWORD) HELPID_DELETE_ARCHIVE :
  534.               (LOWORD(wParam) == IDM_RENAME_ARCHIVE)  ? (DWORD) HELPID_RENAME_ARCHIVE :
  535.               (LOWORD(wParam) == IDM_MAKE_DIR)  ? (DWORD) HELPID_MAKEDIR_HELP :
  536.               (LOWORD(wParam) == IDM_MAKEDIR_HELP)  ? (DWORD) HELPID_MAKEDIR_HELP :
  537.               (LOWORD(wParam) == IDM_SAVE_AS_DEFAULT)  ? (DWORD) HELPID_SAVE_AS_DEFAULT :
  538.                                       (DWORD) 0L;
  539.  
  540.             if (!dwHelpContextId)
  541.                {
  542.                MessageBox( hWnd, "Help not available for Help Menu item",
  543.                           "Help Example", MB_OK);
  544.                return DefWindowProc(hWnd, wMessage, wParam, lParam);
  545.                }
  546.  
  547.             uf.fHelp = FALSE;
  548.             WinHelp(hWnd,szHelpFileName,HELP_CONTEXT,dwHelpContextId);
  549.         }
  550.         else /* not in help mode */
  551.         {
  552.       RECT  rClient;
  553.             switch (LOWORD(wParam))
  554.             {
  555.             case IDM_OPEN:
  556.                 /* If unzipping separately and previous file exists,
  557.                  * go to directory where archive lives.
  558.                  */
  559.                 if ( uf.fCanDragDrop )
  560.                     DragAcceptFiles( hWnd, FALSE );
  561.  
  562.             /* If not unzipping to same directory as archive and
  563.              * file already open, go to where file lives.
  564.              * If extracting to different directory, return to
  565.              * that directory after selecting archive to open.
  566.              */
  567.             if (lpumb->szUnzipFromDirName[0])
  568.                {
  569.                lstrcpy(lpumb->szDirName, lpumb->szUnzipFromDirName);
  570.                }
  571.             if (lpumb->szFileName[0])
  572.                {
  573.                /* strip off filename to make directory name    */
  574.                GetArchiveDir(lpumb->szDirName);
  575.                }
  576.             else
  577.                {
  578.                if (!lpumb->szUnzipFromDirName[0])
  579.                   lpumb->szDirName[0] = '\0'; /* assume no dir   */
  580.                }
  581.             lpumb->szBuffer[0] = '\0';
  582. #ifndef WIN32
  583.             _fmemset(&lpumb->ofn, '\0', sizeof(OPENFILENAME)); /* initialize struct */
  584. #else
  585.             memset(&lpumb->ofn, '\0', sizeof(OPENFILENAME)); /* initialize struct */
  586. #endif
  587.             lpumb->ofn.lStructSize = sizeof(OPENFILENAME);
  588.             lpumb->ofn.hwndOwner = hWnd;
  589.             lpumb->ofn.lpstrFilter = "Zip Files (*.zip)\0*.zip\0Self-extracting Files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0\0";
  590.             lpumb->ofn.nFilterIndex = 1;
  591.             lpumb->ofn.lpstrFile = lpumb->szFileName;
  592.             lpumb->szFileName[0] = '\0';   /* no initial filename   */
  593.             lpumb->ofn.nMaxFile = WIZUNZIP_MAX_PATH;
  594.             lpumb->ofn.lpstrFileTitle = lpumb->szBuffer; /* ignored */
  595.             lpumb->ofn.lpstrInitialDir = (LPSTR)(!lpumb->szDirName[0] ? NULL : lpumb->szDirName);
  596.  
  597.             lpumb->ofn.nMaxFileTitle = OPTIONS_BUFFER_LEN;
  598.             lpumb->ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST |
  599.                    OFN_HIDEREADONLY;
  600.             dwCommDlgHelpId = HELPID_OPEN; /* specify correct help for open dlg   */
  601. #if defined (CRYPT) && !defined (USEWIZUNZDLL)
  602.             /*
  603.              This if statement insures that when you go between zip files,
  604.              the password is nulled out. Not necessary if using dll.
  605.             */
  606.             if (G.key)
  607.                G.key = (char *)NULL;
  608. #endif
  609.             if (GetOpenFileName(&lpumb->ofn))   /* if successful file open  */
  610.                {
  611.                AnsiToOem(lpumb->szFileName, lpumb->szFileName); /* retain as OEM */
  612.                GetArchiveDir(lpumb->szDirName); /* get archive dir name in ANSI */
  613.                /*
  614.                Save the last "unzip from" directory
  615.                */
  616.                if (lpumb->szUnzipFromDirName[1] == ':')
  617.                   drive = lpumb->szUnzipFromDirName[0];
  618.                else
  619.                   drive = '\0';
  620.  
  621.                if (uf.fSaveUnZipFromDir &&
  622.                   (toupper(drive) != 'A') &&
  623.                   (toupper(drive) != 'B'))
  624.                   {
  625.                   lstrcpy(lpumb->szUnzipFromDirName, lpumb->szDirName);
  626.                   if (lpumb->szUnzipFromDirName[strlen(lpumb->szUnzipFromDirName)-1]
  627.                      == ':')
  628.                      lstrcat(lpumb->szUnzipFromDirName, "\\");
  629.                   WritePrivateProfileString(szAppName, szDefaultUnzipFromDir,
  630.                                  lpumb->szUnzipFromDirName, szWizUnzipIniFile);
  631.                   }
  632.                else
  633.                   WritePrivateProfileString(szAppName, szDefaultUnzipFromDir,
  634.                                  "", szWizUnzipIniFile);
  635.                if (uf.fUnzipToZipDir || /* unzipping to same directory as archive */
  636.                   lpumb->szUnzipToDirName[0] == '\0') /* or no default */
  637.                   {
  638.                   /* strip off filename to make directory name    */
  639.                   lstrcpy(lpumb->szUnzipToDirName, lpumb->szDirName);
  640.                   }
  641.                }
  642.                UpdateListBox(hWnd); /* fill in list box */
  643.                SendMessage(hWndList, LB_SETSEL, 1, 0L);
  644.                UpdateButtons(hWnd); /* update state of buttons */
  645.  
  646.                /* Update archive totals area */
  647.                WinAssert(hWndList);
  648.                GetClientRect( hWndList, &rClient );
  649.                OffsetRect( &rClient, 0, dyChar );
  650.                rClient.top = rClient.bottom;
  651.                rClient.bottom = rClient.top + (6*dyChar);
  652.                InvalidateRect( hWnd, &rClient, TRUE);
  653.                UpdateWindow( hWnd );
  654.                SetCaption(hWnd);
  655.                if ( uf.fCanDragDrop )
  656.                   DragAcceptFiles( hWnd, TRUE );
  657.                break;
  658.  
  659.             case IDM_CHDIR:
  660.                 if ( uf.fCanDragDrop )
  661.                     DragAcceptFiles( hWnd, FALSE );
  662.  
  663. #ifndef WIN32
  664.                 _fmemset(&lpumb->ofn, '\0', sizeof(OPENFILENAME)); /* initialize struct */
  665. #else
  666.                 memset(&lpumb->ofn, '\0', sizeof(OPENFILENAME)); /* initialize struct */
  667. #endif
  668.                 lpumb->ofn.lStructSize = sizeof(OPENFILENAME);
  669.                 lpumb->ofn.hwndOwner = hWnd;
  670.                 lpumb->ofn.hInstance = hInst;
  671.                 lpumb->ofn.lpstrFilter = "All Files (*.*)\0*.*\0\0";
  672.                 lpumb->ofn.nFilterIndex = 1;
  673.                 lstrcpy(lpumb->szUnzipToDirNameTmp, lpumb->szUnzipToDirName); /* initialize */
  674.                 { /* Braces are here to allow the declaration of uDirNameLen */
  675. #ifndef WIN32
  676.             size_t uDirNameLen = _fstrlen(lpumb->szUnzipToDirNameTmp);
  677. #else
  678.             size_t uDirNameLen = strlen(lpumb->szUnzipToDirNameTmp);
  679. #endif
  680.                /* If '\\' not at end of directory name, add it now.
  681.                 */
  682.                 if (uDirNameLen > 0 && lpumb->szUnzipToDirNameTmp[uDirNameLen-1] != '\\')
  683.                    lstrcat(lpumb->szUnzipToDirNameTmp, "\\");
  684.                 }
  685.                 lstrcat(lpumb->szUnzipToDirNameTmp,
  686.                     "johnny\376\376.\375\374\373"); /* fake name */
  687.                 lpumb->ofn.lpstrFile = lpumb->szUnzipToDirNameTmp; /* result goes here! */
  688.                 lpumb->ofn.nMaxFile = WIZUNZIP_MAX_PATH;
  689.                 lpumb->ofn.lpstrFileTitle = NULL;
  690.                 lpumb->ofn.nMaxFileTitle = OPTIONS_BUFFER_LEN; /* ignored ! */
  691.                 lpumb->ofn.lpstrInitialDir = lpumb->szUnzipToDirName;
  692.                 lpumb->ofn.lpstrTitle = (LPSTR)"Unzip To";
  693.                 lpumb->ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_ENABLEHOOK |
  694.                            OFN_HIDEREADONLY|OFN_ENABLETEMPLATE|OFN_NOCHANGEDIR;
  695. #ifndef WIN32
  696.                 lpfnSelectDir =
  697.                   MakeProcInstance((FARPROC)SelectDirProc, hInst);
  698. #ifndef MSC
  699.                 (UINT CALLBACK *)lpumb->ofn.lpfnHook = (UINT CALLBACK *)lpfnSelectDir;
  700. #else
  701.                 lpumb->ofn.lpfnHook = lpfnSelectDir;
  702. #endif
  703.  
  704. #else
  705.                 lpumb->ofn.lpfnHook = (LPOFNHOOKPROC)SelectDirProc;
  706. #endif
  707.                 lpumb->ofn.lpTemplateName = "SELDIR";   /* see seldir.dlg   */
  708.                 dwCommDlgHelpId = HELPID_CHDIR; /* in case user hits "help" button */
  709.                 if (GetSaveFileName(&lpumb->ofn)) /* successfully got dir name ? */
  710.                    {
  711. #ifndef WIN32
  712.                    ptr = _fstrrchr(lpumb->ofn.lpstrFile, '\\');
  713. #else
  714.                    ptr = strrchr(lpumb->ofn.lpstrFile, '\\');
  715. #endif
  716.                    if (ptr != NULL)
  717.                       lpumb->ofn.lpstrFile[(int)(ptr - lpumb->ofn.lpstrFile)] = '\0';
  718.                    lstrcpy(lpumb->szUnzipToDirName, lpumb->ofn.lpstrFile); /* save result */
  719.  
  720.                    if (lpumb->szUnzipToDirName[1] == ':')
  721.                       {
  722.                       drive = lpumb->szUnzipToDirName[0];
  723.                       if (lstrlen(lpumb->szUnzipToDirName) == 2)
  724.                          { /* We only have a drive letter and a colon */
  725.                          lstrcat(lpumb->szUnzipToDirName, "\\");
  726.                          }
  727.                       }
  728.                    else
  729.                       drive = '\0';
  730.                    if (uf.fSaveUnZipToDir &&
  731.                       (toupper(drive) != 'A') &&
  732.                       (toupper(drive) != 'B'))
  733.                        {
  734.                   /* MW: Always save last directory written to */
  735.                        WritePrivateProfileString(szAppName, szDefaultUnzipToDir,
  736.                           lpumb->szUnzipToDirName, szWizUnzipIniFile);
  737.                        }
  738.                    SetCaption(hWnd);
  739.                    }
  740.                 else /* either real error or canceled */
  741.                    {
  742.                    DWORD dwExtdError = CommDlgExtendedError(); /* debugging */
  743.  
  744.                    if (dwExtdError != 0L) /* if not canceled then real error */
  745.                       {
  746.                       wsprintf (lpumb->szBuffer, szCantChDir, dwExtdError);
  747.                       MessageBox (hWnd, lpumb->szBuffer, szAppName, MB_ICONINFORMATION | MB_OK);
  748.                       }
  749.                    else
  750.                       {
  751.                       RECT mRect;
  752.  
  753.                       GetWindowRect(hWndMain, &mRect);
  754.                       InvalidateRect(hWndMain, &mRect, TRUE);
  755.                       SendMessage(hWndMain, WM_SIZE, SIZE_RESTORED,
  756.                         MAKELONG(mRect.right-mRect.left, mRect.top-mRect.bottom));
  757.                       UpdateWindow(hWndMain);
  758.                       }
  759.                    }
  760. #ifndef WIN32
  761.                 FreeProcInstance(lpfnSelectDir);
  762. #endif
  763.                 if ( uf.fCanDragDrop )
  764.                     DragAcceptFiles( hWnd, TRUE );
  765.                 break;
  766.  
  767.             case IDM_DELETE_ARCHIVE:
  768.                 {
  769.                 char szStr[WIZUNZIP_MAX_PATH];
  770.                 if ( uf.fCanDragDrop )
  771.                     DragAcceptFiles( hWnd, FALSE );
  772.                 sprintf(szStr, "Are you sure you want to delete\n%s", lpumb->szFileName);
  773.                 if (MessageBox(hWnd, szStr, "Deleting File", MB_ICONSTOP | MB_OKCANCEL) == IDOK)
  774.                    {
  775.                    remove(lpumb->szFileName);
  776.                    fprintf(stdout,"Deleting %s\n", lpumb->szFileName);
  777.                    SendMessage(hWndList, LB_RESETCONTENT, 0, 0);
  778.                    lpumb->szFileName[0] = '\0';
  779.                    SetCaption(hWnd);
  780.                    UpdateButtons(hWnd); /* update state of buttons */
  781.                    }
  782.                 if ( uf.fCanDragDrop )
  783.                   DragAcceptFiles( hWnd, TRUE );
  784.                 break;
  785.                 }
  786.             case IDM_MOVE_ARCHIVE:
  787.                 /*
  788.                  * Yes - this can be done under Win32 differently, but
  789.                  * you have to go through some hoops, and this just makes
  790.                  * it easier.
  791.                  */
  792.                 move_flag = TRUE;
  793.                 dwCommDlgHelpId = HELPID_MOVE_ARCHIVE; /* in case user hits "help" button */
  794.             case IDM_RENAME_ARCHIVE:
  795.                 if (!move_flag)
  796.                    {
  797.                    rename_flag = TRUE;
  798.                    dwCommDlgHelpId = HELPID_RENAME_ARCHIVE; /* in case user hits "help" button */
  799.                    }
  800.             case IDM_COPY_ARCHIVE:
  801.                 if ( uf.fCanDragDrop )
  802.                     DragAcceptFiles( hWnd, FALSE );
  803.                 if ((!move_flag) && (!rename_flag))
  804.                    dwCommDlgHelpId = HELPID_COPY_ARCHIVE; /* in case user hits "help" button */
  805.                 CopyArchive(hWnd, move_flag, rename_flag);
  806.                 if ( uf.fCanDragDrop )
  807.                     DragAcceptFiles( hWnd, TRUE );
  808.                 move_flag = FALSE;
  809.                 rename_flag = FALSE;
  810.                 break;
  811.  
  812.             case IDM_EXIT:
  813.                 SendMessage(hWnd, WM_CLOSE, 0, 0L);
  814.                 break;
  815.  
  816.             case IDM_HELP:  /* Display Help */
  817.                 WinHelp(hWnd,szHelpFileName,HELP_INDEX,0L);
  818.                 break;
  819.  
  820.             case IDM_HELP_HELP:
  821.                 WinHelp(hWnd,"WINHELP.HLP",HELP_INDEX,0L);
  822.                 break;
  823.  
  824.             case IDM_ABOUT:
  825.                 if ( uf.fCanDragDrop )
  826.                     DragAcceptFiles( hWnd, FALSE );
  827. #ifndef WIN32
  828.                 lpfnAbout = MakeProcInstance(AboutProc, hInst);
  829.                 DialogBox(hInst, "About", hWnd, lpfnAbout);
  830.                 FreeProcInstance(lpfnAbout);
  831. #else
  832.                 DialogBox(hInst, "About", hWnd, AboutProc);
  833. #endif
  834.                 if ( uf.fCanDragDrop )
  835.                     DragAcceptFiles( hWnd, TRUE );
  836.                 break;
  837.  
  838.             case IDM_LISTBOX:       /* command from listbox     */
  839.                 if (cZippedFiles)
  840.                 {
  841.                     switch (GET_WM_COMMAND_CMD(wParam, lParam))
  842.                     {
  843.                     case LBN_SELCHANGE:
  844.                         UpdateButtons(hWnd);
  845.                         break;
  846.                     case LBN_DBLCLK:
  847.                         UpdateButtons(hWnd);
  848.                         if ( uf.fCanDragDrop )
  849.                             DragAcceptFiles( hWnd, FALSE );
  850.  
  851.                         if (uf.fAutoClearStatus && wLBSelection == IDM_LB_DISPLAY) /* if autoclear on display */
  852.                            SendMessage(hWndStatus, WM_COMMAND, IDM_CLEAR_STATUS, 0L);
  853.  
  854.                         Action(hWnd, (WPARAM)(wLBSelection - IDM_LB_EXTRACT));
  855.                         if ( uf.fCanDragDrop )
  856.                             DragAcceptFiles( hWnd, TRUE );
  857.                         break;
  858.                     }
  859.                 }
  860.                 break;
  861.             case IDM_LONG:
  862.             case IDM_SHORT:
  863.                 /* If format change, uncheck old, check new. */
  864.                 if ((LOWORD(wParam) - IDM_SHORT) != (signed int)uf.fFormatLong)
  865.                 {
  866.                     WPARAM wFormatTmp = (WPARAM)(LOWORD(wParam)  - IDM_SHORT);
  867.                     int __far *pnSelItems; /* pointer to list of selected items */
  868.                     HANDLE  hnd = 0;
  869.                     int cSelLBItems ; /* no. selected items in listbox */
  870.                     RECT    rClient;
  871.  
  872.                     cSelLBItems = CLBItemsGet(hWndList, &pnSelItems, &hnd);
  873.                     CheckMenuItem(hMenu, (IDM_SHORT+uf.fFormatLong), MF_BYCOMMAND|MF_UNCHECKED);
  874.                     CheckMenuItem(hMenu, (IDM_SHORT+wFormatTmp), MF_BYCOMMAND|MF_CHECKED);
  875.                     uf.fFormatLong = wFormatTmp;
  876.                     UpdateListBox(hWnd);
  877.  
  878.                     SizeWindow(hWnd, TRUE);
  879.                     WritePrivateProfileString(szAppName, szFormatKey,
  880.                                 (LPSTR)(szFormatKeyword[uf.fFormatLong]), szWizUnzipIniFile);
  881.              
  882.                     /* anything previously selected ? */
  883.                     if (cSelLBItems > 0)
  884.                     {
  885.                         ReselectLB(hWndList, cSelLBItems, pnSelItems);
  886.                         GlobalUnlock(hnd);
  887.                         GlobalFree(hnd);
  888.                     }
  889.  
  890.                     /* enable or disable buttons */
  891.                     UpdateButtons(hWnd);
  892.  
  893.                     /* make sure labels & Zip archive totals get updated */
  894.                     WinAssert(hWnd);
  895.                     GetClientRect( hWnd, &rClient );
  896.                     rClient.top = 0;
  897.                     rClient.bottom = rClient.top + (4*dyChar);
  898.                     InvalidateRect( hWnd, &rClient, TRUE);
  899.                     WinAssert(hWndList);
  900.                     GetClientRect( hWndList, &rClient );
  901.                     OffsetRect( &rClient, 0, dyChar );
  902.                     rClient.top = rClient.bottom;
  903.                     rClient.bottom = rClient.top + (4*dyChar);
  904.                     InvalidateRect( hWnd, &rClient, TRUE);
  905.                     UpdateWindow( hWnd );
  906.                 }
  907.                 break;
  908.             case IDM_PROMPT_TO_OVERWRITE:
  909.                 lpDCL->PromptToOverwrite = !lpDCL->PromptToOverwrite;
  910.                 CheckMenuItem(hMenu,IDM_PROMPT_TO_OVERWRITE,MF_BYCOMMAND|
  911.                    (lpDCL->PromptToOverwrite) ? MF_CHECKED: MF_UNCHECKED);
  912.                 if (lpDCL->PromptToOverwrite)
  913.                    {
  914.                    CheckMenuItem(hMenu,IDM_EXTRACT_ONLY_NEWER,
  915.                         MF_BYCOMMAND|MF_UNCHECKED);
  916.                    CheckMenuItem(hMenu,IDM_OVERWRITE,
  917.                         MF_BYCOMMAND|MF_UNCHECKED);
  918.                    EnableMenuItem(hMenu, IDM_EXTRACT_ONLY_NEWER,
  919.                         MF_DISABLED|MF_GRAYED|MF_BYCOMMAND);
  920.                    ModifyMenu(hMenu, IDM_OVERWRITE, MF_BYCOMMAND |
  921.                         MF_DISABLED|MF_GRAYED, IDM_OVERWRITE,
  922.                         "Never Overwrite Existing Files");
  923.                    lpDCL->Overwrite = FALSE;
  924.                    WritePrivateProfileString(szAppName, szOverwriteKey,
  925.                         (LPSTR)(lpDCL->Overwrite ? szYes : szNo ),
  926.                         szWizUnzipIniFile);
  927.                    EnableMenuItem(hMenu, IDM_OVERWRITE,
  928.                         MF_DISABLED|MF_GRAYED|MF_BYCOMMAND);
  929.                    }
  930.                 else
  931.                    {
  932.                    CheckMenuItem(hMenu,IDM_EXTRACT_ONLY_NEWER,MF_BYCOMMAND|
  933.                                 (WORD)(lpDCL->ExtractOnlyNewer ? MF_CHECKED: MF_UNCHECKED));
  934.                    CheckMenuItem(hMenu,IDM_OVERWRITE,MF_BYCOMMAND|MF_CHECKED);
  935.                    EnableMenuItem(hMenu, IDM_OVERWRITE, MF_ENABLED|MF_BYCOMMAND);
  936.                    EnableMenuItem(hMenu, IDM_EXTRACT_ONLY_NEWER, MF_ENABLED|MF_BYCOMMAND);
  937.                    }
  938.                 WritePrivateProfileString(szAppName, szPromptOverwriteKey,
  939.                         (LPSTR)(lpDCL->PromptToOverwrite ? szYes : szNo ), szWizUnzipIniFile);
  940.                 break;
  941.  
  942.             case IDM_OVERWRITE:
  943.                 /* Toggle value of overwrite flag. */
  944.                 lpDCL->Overwrite = !lpDCL->Overwrite;
  945.                 ModifyMenu(hMenu, IDM_OVERWRITE, MF_BYCOMMAND |
  946.                       MF_ENABLED, IDM_OVERWRITE,
  947.                       (lpDCL->Overwrite ? "Always Overwrite Existing Files":
  948.                         "Never Overwrite Existing Files"));
  949.                 CheckMenuItem(hMenu,IDM_OVERWRITE,MF_BYCOMMAND|MF_CHECKED);
  950.                 WritePrivateProfileString(szAppName, szOverwriteKey,
  951.                         (LPSTR)(lpDCL->Overwrite ? szYes : szNo ), szWizUnzipIniFile);
  952.                 break;
  953.  
  954.             case IDM_EXTRACT_ONLY_NEWER:
  955.                 /* Toggle value of extract_only_newer flag. */
  956.                 lpDCL->ExtractOnlyNewer = !lpDCL->ExtractOnlyNewer;
  957.                 CheckMenuItem(hMenu,IDM_EXTRACT_ONLY_NEWER,MF_BYCOMMAND|
  958.                                 (WORD)(lpDCL->ExtractOnlyNewer ? MF_CHECKED: MF_UNCHECKED));
  959.                 WritePrivateProfileString(szAppName, szExtractOnlyNewerKey,
  960.                         (LPSTR)(lpDCL->ExtractOnlyNewer ? szYes : szNo ), szWizUnzipIniFile);
  961.                 break;
  962.  
  963.             case IDM_TRANSLATE:
  964.                 /* Toggle value of translate flag. */
  965.                 uf.fTranslate = !uf.fTranslate;
  966.                 CheckMenuItem(hMenu,IDM_TRANSLATE,MF_BYCOMMAND|
  967.                                 (WORD)(uf.fTranslate ? MF_CHECKED: MF_UNCHECKED));
  968.                 WritePrivateProfileString(szAppName, szTranslateKey,
  969.                         (LPSTR)(uf.fTranslate ? szYes : szNo ), szWizUnzipIniFile);
  970.                 break;
  971.  
  972.             case IDM_SPACE_TO_UNDERSCORE:
  973.                 /* Toggle value of space to underscore flag. */
  974.                 lpDCL->SpaceToUnderscore = !lpDCL->SpaceToUnderscore;
  975.                 CheckMenuItem(hMenu,IDM_SPACE_TO_UNDERSCORE,MF_BYCOMMAND|
  976.                                 (WORD)(lpDCL->SpaceToUnderscore ? MF_CHECKED: MF_UNCHECKED));
  977.                 WritePrivateProfileString(szAppName, szSpaceToUnderscoreKey,
  978.                         (LPSTR)(lpDCL->SpaceToUnderscore ? szYes : szNo ), szWizUnzipIniFile);
  979.                 break;
  980.  
  981.             case IDM_SAVE_UNZIP_TO_DIR:
  982.                 /* Toggle value of fSaveUnzipToDir flag. */
  983.                 uf.fSaveUnZipToDir = !uf.fSaveUnZipToDir;
  984.                 CheckMenuItem(hMenu,IDM_SAVE_UNZIP_TO_DIR,MF_BYCOMMAND|
  985.                                 (WORD)(uf.fSaveUnZipToDir ? MF_CHECKED: MF_UNCHECKED));
  986.                 WritePrivateProfileString(szAppName, szSaveUnZipToKey,
  987.                         (LPSTR)(uf.fSaveUnZipToDir ? szYes : szNo ), szWizUnzipIniFile);
  988.                 if (uf.fSaveUnZipToDir)
  989.                    WritePrivateProfileString(szAppName, szDefaultUnzipToDir,
  990.                          "", szWizUnzipIniFile);
  991.                 break;
  992.  
  993.             case IDM_SAVE_UNZIP_FROM_DIR:
  994.                 /* Toggle value of fSaveUnzipToDir flag. */
  995.                 uf.fSaveUnZipFromDir = !uf.fSaveUnZipFromDir;
  996.                 CheckMenuItem(hMenu,IDM_SAVE_UNZIP_FROM_DIR,MF_BYCOMMAND|
  997.                                 (WORD)(uf.fSaveUnZipFromDir ? MF_CHECKED: MF_UNCHECKED));
  998.                 WritePrivateProfileString(szAppName, szSaveUnZipFromKey,
  999.                         (LPSTR)(uf.fSaveUnZipFromDir ? szYes : szNo ), szWizUnzipIniFile);
  1000.                 if (uf.fSaveUnZipFromDir)
  1001.                    WritePrivateProfileString(szAppName, szDefaultUnzipFromDir,
  1002.                          "", szWizUnzipIniFile);
  1003.                 break;
  1004.  
  1005.             case IDM_UNZIP_TO_ZIP_DIR:
  1006.                 /* toggle value of Unzip to .ZIP  */
  1007.                 uf.fUnzipToZipDir = !uf.fUnzipToZipDir;
  1008.                 CheckMenuItem(hMenu,IDM_UNZIP_TO_ZIP_DIR,MF_BYCOMMAND|
  1009.                                     (WORD)(uf.fUnzipToZipDir ? MF_CHECKED:MF_UNCHECKED));
  1010.                 EnableMenuItem(hMenu,IDM_CHDIR,MF_BYCOMMAND|
  1011.                                     (WORD)(uf.fUnzipToZipDir ? MF_GRAYED:MF_ENABLED));
  1012.                 WritePrivateProfileString(szAppName, szUnzipToZipDirKey,
  1013.                             (LPSTR)(uf.fUnzipToZipDir ? szYes : szNo ), szWizUnzipIniFile);
  1014.  
  1015.                 if (uf.fUnzipToZipDir && lpumb->szDirName[0])
  1016.                 {
  1017.                     lstrcpy(lpumb->szUnzipToDirName, lpumb->szDirName); /* get new dirname */
  1018.                    SetCaption(hWnd);
  1019.                 }
  1020.                 break;
  1021.             case IDM_MAKE_DIR:
  1022.                {
  1023.                FARPROC lpfnMakeDir;
  1024.                dwCommDlgHelpId = HELPID_MAKEDIR_HELP; /* if someone hits help */
  1025.                lpfnMakeDir = MakeProcInstance(MakeDirProc, hInst);
  1026.                DialogBox(hInst, "MAKEDIR", hWnd, lpfnMakeDir);
  1027. #ifndef WIN32
  1028.                FreeProcInstance(lpfnMakeDir);
  1029. #endif
  1030.                }
  1031.                break;
  1032.             case IDM_SOUND_OPTIONS: /* launch Sound Options dialog box   */
  1033.              {
  1034.             FARPROC lpfnSoundOptions;
  1035.             dwCommDlgHelpId = HELPID_SOUND_OPTIONS; /* if someone hits "help" */
  1036.                 lpfnSoundOptions = MakeProcInstance(SoundProc, hInst);
  1037.                 DialogBox(hInst, "SOUND", hWnd, lpfnSoundOptions);
  1038. #ifndef WIN32
  1039.                 FreeProcInstance(lpfnSoundOptions);
  1040. #endif
  1041.             }
  1042.                 break;
  1043.  
  1044.            case IDM_AUTOCLEAR_STATUS:
  1045.                 /* automatically clear status window before displaying  */
  1046.                 uf.fAutoClearStatus = !uf.fAutoClearStatus;
  1047.                 CheckMenuItem(hMenu,IDM_AUTOCLEAR_STATUS,MF_BYCOMMAND|
  1048.                                     (WORD)(uf.fAutoClearStatus ? MF_CHECKED:MF_UNCHECKED));
  1049.                 WritePrivateProfileString(szAppName, szAutoClearStatusKey,
  1050.                             (LPSTR)(uf.fAutoClearStatus ? szYes : szNo ), szWizUnzipIniFile);
  1051.  
  1052.                  break;
  1053.  
  1054.            case IDM_AUTOCLEAR_DISPLAY:
  1055.                uf.fAutoClearDisplay = !uf.fAutoClearDisplay;
  1056.                CheckMenuItem(hMenu,IDM_AUTOCLEAR_DISPLAY,MF_BYCOMMAND|
  1057.                                     (WORD)(uf.fAutoClearDisplay ? MF_CHECKED:MF_UNCHECKED));
  1058.                 WritePrivateProfileString(szAppName, szAutoClearDisplayKey,
  1059.                             (LPSTR)(uf.fAutoClearDisplay ? szYes : szNo ), szWizUnzipIniFile);
  1060.                break;
  1061.   
  1062.             case IDM_LB_EXTRACT:
  1063.             case IDM_LB_DISPLAY:
  1064.             case IDM_LB_TEST:
  1065.                 /* If overwrite change, uncheck old, check new. */
  1066.                 /* wParam is the new default action */
  1067.                 if (LOWORD(wParam) != wLBSelection)
  1068.                    {
  1069.                    RECT    rClient, rButton;
  1070.                    POINT   ptUpperLeft, ptLowerRight;
  1071.  
  1072.                    CheckMenuItem(hMenu,wLBSelection,MF_BYCOMMAND|MF_UNCHECKED);
  1073.                    CheckMenuItem(hMenu,wParam,MF_BYCOMMAND|MF_CHECKED);
  1074.  
  1075.                    wLBSelection = LOWORD(wParam);
  1076.                    WritePrivateProfileString(szAppName, szLBSelectionKey,
  1077.                         (LPSTR)(LBSelectionTable[LOWORD(wParam) - IDM_LB_EXTRACT]), szWizUnzipIniFile);
  1078.                    WinAssert(hWnd);
  1079.                    GetClientRect(hWnd, &rClient);
  1080.                    GetWindowRect(hExtract, &rButton); /* any button will do */
  1081.                    ptUpperLeft.x = rButton.left;
  1082.                    ptUpperLeft.y = rButton.top;
  1083.                    ptLowerRight.x = rButton.right;
  1084.                    ptLowerRight.y = rButton.bottom;
  1085.                    ScreenToClient(hWnd, &ptUpperLeft);
  1086.                    ScreenToClient(hWnd, &ptLowerRight);
  1087.                    rClient.top = ptUpperLeft.y;
  1088.                    rClient.bottom = ptLowerRight.y;
  1089.                    InvalidateRect( hWnd, &rClient, TRUE); /* redraw button area */
  1090.                    UpdateWindow( hWnd );
  1091.  
  1092.  
  1093.                    }
  1094.                 break;
  1095.  
  1096.             case IDM_SHOW_COMMENT:
  1097.                 /* display the archive comment in mesg window */
  1098.                 if ( uf.fCanDragDrop )
  1099.                     DragAcceptFiles( hWnd, FALSE );
  1100.                 DisplayComment(hWnd);
  1101.                 if ( uf.fCanDragDrop )
  1102.                     DragAcceptFiles( hWnd, TRUE );
  1103.                 break;
  1104.  
  1105.             case IDM_RECR_DIR_STRUCT:
  1106.                 /* re-create directories structure */
  1107.                 uf.fRecreateDirs = !uf.fRecreateDirs;
  1108.                 CheckMenuItem(hMenu, IDM_RECR_DIR_STRUCT,
  1109.                  MF_BYCOMMAND | (uf.fRecreateDirs ? MF_CHECKED : MF_UNCHECKED));
  1110.                 WritePrivateProfileString(szAppName, szRecreateDirsKey,
  1111.                                     (LPSTR)(uf.fRecreateDirs ? szYes : szNo), szWizUnzipIniFile);
  1112.                 break;
  1113.  
  1114.             case IDM_SHOW_BUBBLE_HELP:
  1115.                 /* Show toolbar help */
  1116.                 uf.fShowBubbleHelp = !uf.fShowBubbleHelp;
  1117.                 CheckMenuItem(hMenu, IDM_SHOW_BUBBLE_HELP,
  1118.                  MF_BYCOMMAND | (uf.fShowBubbleHelp ? MF_CHECKED : MF_UNCHECKED));
  1119.                 WritePrivateProfileString(szAppName, szShowBubbleHelpKey,
  1120.                                     (LPSTR)(uf.fShowBubbleHelp ? szYes : szNo), szWizUnzipIniFile);
  1121.                 break;
  1122.  
  1123.             case IDM_DISPLAY:
  1124.             case IDM_TEST:
  1125.             case IDM_EXTRACT:
  1126.                 if ( uf.fCanDragDrop )
  1127.                     DragAcceptFiles( hWnd, FALSE );
  1128.  
  1129.                 if (uf.fAutoClearStatus && LOWORD(wParam) == IDM_DISPLAY) /* if autoclear on display */
  1130.                    SendMessage(hWndStatus, WM_COMMAND, IDM_CLEAR_STATUS, 0L);
  1131.  
  1132.                 Action(hWnd, (WPARAM)(LOWORD(wParam) - IDM_EXTRACT));
  1133.                 if ( uf.fCanDragDrop )
  1134.                     DragAcceptFiles( hWnd, TRUE );
  1135.                 break;
  1136.  
  1137.             case IDM_SELECT_ALL:
  1138.             case IDM_DESELECT_ALL:
  1139.                 if (cZippedFiles)
  1140.                    {
  1141.                    SendMessage(hWndList , LB_SELITEMRANGE,
  1142.                           (WPARAM)(LOWORD(wParam) == IDM_DESELECT_ALL ? FALSE : TRUE),
  1143.                           MAKELONG(0, (cZippedFiles-1)));
  1144.                    UpdateButtons(hWnd);
  1145.                    }
  1146.                 break;
  1147.  
  1148.          case IDM_SELECT_BY_PATTERN:
  1149.             if (!hPatternSelectDlg)
  1150.                {
  1151.                DLGPROC lpfnPatternSelect;
  1152.  
  1153.                dwCommDlgHelpId = HELPID_SELECT_BY_PATTERN;
  1154.                lpfnPatternSelect = (DLGPROC)MakeProcInstance(PatternSelectProc, hInst);
  1155.                WinAssert(lpfnPatternSelect)
  1156.                hPatternSelectDlg =
  1157.                CreateDialog(hInst, "PATTERN", hWnd, lpfnPatternSelect);
  1158.                WinAssert(hPatternSelectDlg);
  1159.                }
  1160.             break;
  1161.  
  1162.          case IDM_COPY: /* copy from "Status" window value to clipboard */
  1163.                CopyStatusToClipboard(hWnd);
  1164.             break;
  1165.  
  1166.          case IDM_CLEAR_STATUS:  /* forward to status window */
  1167.             PostMessage(hWndStatus, WM_COMMAND, IDM_CLEAR_STATUS, 0L);
  1168.             EnableWindow(hCopyStatus, FALSE);
  1169.             EnableMenuItem(hMenu, IDM_COPY, MF_GRAYED);
  1170.             break;
  1171.  
  1172.          case IDM_MAX_LISTBOX:
  1173.          case IDM_MAX_STATUS:
  1174.          case IDM_SPLIT:
  1175.             {
  1176.             RECT rClient;
  1177.             if (wWindowSelection != LOWORD(wParam) ) /* If state change */
  1178.                {
  1179.                CheckMenuItem(hMenu, wWindowSelection, MF_BYCOMMAND | MF_UNCHECKED);
  1180.                switch (wWindowSelection)
  1181.                   {
  1182.                   case IDM_MAX_STATUS:
  1183.                      ManageStatusWnd(IDM_SPLIT);
  1184.                      break;
  1185.  
  1186.                   case IDM_MAX_LISTBOX: /* status window has been hidden */
  1187.                      WinAssert(hWndStatus);
  1188.                      EnableWindow( hWndStatus, TRUE );
  1189.                      ShowWindow(hWndStatus, SW_SHOWNORMAL);
  1190.                      wWindowSelection = IDM_SPLIT; /* save new state   */
  1191.                      SizeWindow(hWnd, FALSE);
  1192.                      break;
  1193.                   }
  1194.  
  1195.                /* listbox and status window are in split state at this point   */
  1196.                switch (LOWORD(wParam))
  1197.                   {
  1198.                   case IDM_MAX_STATUS:
  1199.                      ManageStatusWnd(wParam);
  1200.                      break;
  1201.  
  1202.                   case IDM_MAX_LISTBOX:
  1203.                      WinAssert(hWndStatus);
  1204.                      EnableWindow( hWndStatus, FALSE );
  1205.                      ShowWindow(hWndStatus, SW_HIDE);
  1206.                      break;
  1207.                   }
  1208.                /* Insure "header" is updated as necessary */
  1209.                WinAssert(hWnd);
  1210.                GetClientRect( hWnd, &rClient );
  1211.                rClient.top = 2 * dyChar;
  1212.                rClient.left += dxChar/2;
  1213.                InvalidateRect(hWnd, &rClient, TRUE);
  1214.                UpdateWindow(hWnd);
  1215.  
  1216.                wWindowSelection = LOWORD(wParam) ; /* save new state   */
  1217.                SizeWindow(hWnd, FALSE);
  1218.                CheckMenuItem(hMenu, wWindowSelection, MF_BYCOMMAND | MF_CHECKED);
  1219.                }
  1220.             break;
  1221.             }
  1222.  
  1223.          case IDM_SETFOCUS_ON_STATUS: /* posted from Action() following extract-to-Status */
  1224.             SetFocus(hWndStatus);   /* set focus on Status so user can scroll */
  1225.             break;
  1226.             default:
  1227.  
  1228.             return DefWindowProc(hWnd, wMessage, wParam, lParam);
  1229.             }
  1230.         } /* bottom of not in help mode */
  1231.         break;
  1232.  
  1233.     case WM_SETCURSOR:
  1234.         /* In help mode it is necessary to reset the cursor in response */
  1235.         /* to every WM_SETCURSOR message.Otherwise, by default, Windows */
  1236.         /* will reset the cursor to that of the window class. */
  1237.  
  1238.         if (uf.fHelp)
  1239.         {
  1240.             SetCursor(hHelpCursor);
  1241.             break;
  1242.         }
  1243.         return DefWindowProc(hWnd, wMessage, wParam, lParam);
  1244.  
  1245.  
  1246.     case WM_INITMENU:
  1247.         if (uf.fHelp)
  1248.            {
  1249.            SetCursor(hHelpCursor);
  1250.            }
  1251.         return TRUE;
  1252.  
  1253.     case WM_ENTERIDLE:
  1254.         if ((LOWORD(wParam) == MSGF_MENU) && (GetKeyState(VK_F1) & 0x8000))
  1255.            {
  1256.            uf.fHelp = TRUE;
  1257.            PostMessage(hWnd, WM_KEYDOWN, VK_RETURN, 0L);
  1258.            }
  1259.         break;
  1260.  
  1261.     case WM_CLOSE:
  1262.         DestroyWindow(hWnd);
  1263.         break;
  1264.  
  1265.     case WM_DESTROY:
  1266.         if ( uf.fCanDragDrop )
  1267.             DragAcceptFiles( hWnd, FALSE );
  1268.         DeleteObject(hBrush);
  1269.         WinHelp(hWnd, szHelpFileName, HELP_QUIT, 0L);
  1270.         PostQuitMessage(0);
  1271.         break;
  1272.  
  1273.     case WM_DROPFILES:
  1274.         {
  1275.         WORD    cFiles;
  1276.  
  1277.         /* Get the number of files that have been dropped */
  1278.         cFiles = (WORD)DragQueryFile( (HDROP)wParam, (UINT)-1, lpumb->szBuffer, (UINT)256);
  1279.  
  1280.         /* Only handle one dropped file until MDI-ness happens */
  1281.         if (cFiles == 1)
  1282.            {
  1283.            RECT    rClient;
  1284.  
  1285.            DragQueryFile( (HDROP)wParam, 0, lpumb->szFileName, WIZUNZIP_MAX_PATH);
  1286.            AnsiToOem(lpumb->szFileName, lpumb->szFileName); /* retain as OEM */
  1287.            GetArchiveDir(lpumb->szDirName); /* get archive dir name in ANSI */
  1288.            if (uf.fUnzipToZipDir || /* unzipping to same directory as archive */
  1289.                lpumb->szUnzipToDirName[0] == '\0') /* or no default */
  1290.               {
  1291.               /* strip off filename to make directory name    */
  1292.               lstrcpy(lpumb->szUnzipToDirName, lpumb->szDirName);
  1293.               }
  1294.            lstrcpy(lpumb->szBuffer, lpumb->szDirName); /* get scratch copy */
  1295.            DlgDirList (hWnd, lpumb->szBuffer, 0, 0, 0); /* change dir */
  1296.            UpdateListBox(hWnd); /* fill in list box */
  1297.            SendMessage(hWndList, LB_SETSEL, 1, 0L);
  1298.            UpdateButtons(hWnd); /* update state of buttons */
  1299.  
  1300.            WinAssert(hWndList);
  1301.            GetClientRect( hWndList, &rClient );
  1302.            OffsetRect( &rClient, 0, dyChar );
  1303.            rClient.top = rClient.bottom;
  1304.            rClient.bottom = rClient.top + (2*dyChar);
  1305.            InvalidateRect( hWnd, &rClient, TRUE);
  1306.            UpdateWindow( hWnd );
  1307.            SetCaption(hWnd);
  1308.            }
  1309.         DragFinish( (HDROP)wParam );
  1310.         }
  1311.         break;
  1312.  
  1313.     case WM_PAINT:
  1314.         if (wWindowSelection != IDM_MAX_STATUS)
  1315.            {
  1316.            PAINTSTRUCT ps;
  1317.            RECT    rClient;
  1318.            DWORD   dwBackColor;
  1319.  
  1320.            hDC = BeginPaint( hWnd, &ps );
  1321.            if ( hDC )
  1322.               {
  1323.               WinAssert(hWndList);
  1324.               GetClientRect( hWndList, &rClient );
  1325.               if (RectVisible( hDC, &rClient ))
  1326.                  UpdateWindow( hWndList );
  1327.               hOldFont = SelectObject ( hDC, hFixedFont);
  1328.  
  1329.               WinAssert(hWnd);
  1330.               GetClientRect( hWnd, &rClient );
  1331.               dwBackColor = SetBkColor(hDC,GetSysColor(BG_SYS_COLOR));
  1332.  
  1333.               /* Move "header" down two lines for button room at top */
  1334.                   rClient.top = 2 * dyChar;
  1335.  
  1336.               rClient.left += dxChar/2;
  1337.                   DrawText( hDC, (LPSTR)Headers[uf.fFormatLong][0], -1,
  1338.                      &rClient, DT_NOPREFIX | DT_TOP);
  1339.  
  1340.               if (lpumb->szFileName[0])   /* if file selected */
  1341.                  {
  1342.                  WinAssert(hWndList);
  1343.                  GetClientRect( hWndList, &rClient );
  1344.                  OffsetRect( &rClient, 0, dyChar+2);
  1345.                  rClient.left += dxChar/2;
  1346.                  /* Move totals "trailer" down two lines for button room */
  1347.                     rClient.top = rClient.bottom + (2 * dyChar);
  1348.  
  1349.                  rClient.bottom = rClient.top + dyChar;
  1350.                  DrawText( hDC, (LPSTR)szTrailers[uf.fFormatLong], -1,
  1351.                    &rClient, DT_NOPREFIX | DT_TOP);
  1352.  
  1353.                  /* Display totals line at bottom of listbox */
  1354.                  rClient.top += dyChar;
  1355.                  rClient.bottom += dyChar;
  1356.  
  1357.                  DrawText( hDC, lpumb->szTotalsLine, -1,
  1358.                     &rClient, DT_NOPREFIX | DT_TOP);
  1359.                  }
  1360.               SetBkColor(hDC, dwBackColor);
  1361.               (void)SelectObject ( hDC, hOldFont);
  1362.             }
  1363.             EndPaint(hWnd, &ps);
  1364.             break;
  1365.         }
  1366.         return DefWindowProc(hWnd, wMessage, wParam, lParam);
  1367.    default:
  1368.       if (wMessage == uCommDlgHelpMsg)   /* common dialog help message ID */
  1369.       {
  1370.             WinHelp(hWnd, szHelpFileName, HELP_CONTEXT, dwCommDlgHelpId );
  1371.          return 0;
  1372.       }
  1373.         return DefWindowProc(hWnd, wMessage, wParam, lParam);
  1374.     }
  1375.     return 0;
  1376. }
  1377.